package com.zib.bilibili.view.fragment;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zib.bilibili.R;
import com.zib.bilibili.base.BaseFragment;
import com.zib.bilibili.customview.XCFlowLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class FindFragment extends BaseFragment {
    @Bind(R.id.layout_header)
    LinearLayout layoutHeader;
    @Bind(R.id.txt_find_search)
    TextView txtFindSearch;
    @Bind(R.id.img_content)
    ImageView imgContent;
    @Bind(R.id.txt_content)
    TextView txtContent;
    @Bind(R.id.layout_content)
    LinearLayout layoutContent;
    private String mNames[] = {
            "极限挑战", "吃货天下", "我的危险妻子",
            "守望先锋", "宇宙夫妇", "暴走大事件",
            "主播真会玩", "我们相爱吧", "在下坂本有何贵干",
            "re:从零开始的异世界生活", "爱来了别错过", "起小点",
            "敖厂长", "不愉快的果实", "蜡笔小新", "逗鱼时刻",
            "99.9", "徐老师来巡山", "超时空要塞",
            "守望先锋", "宇宙夫妇", "暴走大事件",
            "主播真会玩", "我们相爱吧", "在下坂本有何贵干",
            "re:从零开始的异世界生活", "爱来了别错过", "起小点",
            "敖厂长", "不愉快的果实", "蜡笔小新", "逗鱼时刻"
    };

    @Bind(R.id.flowlayout)
    XCFlowLayout mFlowLayout;

    public FindFragment() {
        // Required empty public constructor
    }

    public static FindFragment newInstance() {
        FindFragment fragment = new FindFragment();
        return fragment;
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_find;
    }

    @Override
    public void initView() {

        initChildViews();

    }

    private void initChildViews() {
        // TODO Auto-generated method stub

        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.leftMargin = 5;
        lp.rightMargin = 5;
        lp.topMargin = 5;
        lp.bottomMargin = 5;
        for (int i = 0; i < mNames.length; i++) {
            TextView view = new TextView(getContext());
            view.setText(mNames[i]);
            view.setTextColor(Color.GRAY);

            view.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_tv_find));
            mFlowLayout.addView(view, lp);
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }




    @OnClick( R.id.layout_content)
    public void onClick() {

        float density = getResources().getDisplayMetrics().density;
        ViewGroup.LayoutParams params=mFlowLayout.getLayoutParams();
                if (txtContent.getText().equals("查看更多")){
                    txtContent.setText("收起");
                    Drawable drawable=getResources().getDrawable(R.drawable.ic_arrow_up);
                    imgContent.setBackground(drawable);
                    params.height=(int) (125*density);
                    mFlowLayout.setLayoutParams(params);
                }else {
                    txtContent.setText("查看更多");
                    Drawable drawable=getResources().getDrawable(R.drawable.ic_arrow_down);
                    imgContent.setBackground(drawable);
                    params.height=(int) (60*density);
                    mFlowLayout.setLayoutParams(params);
                }


    }
}
